package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.Application;
import com.huadi.firematerialident.po.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class ApplicationDaoImpl implements ApplicationDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addApplication(Application Application) {
        String sql="insert into Application values(?,?,?,?,?,now(),'否',1,now())";
        return jdbcTemplate.update(sql,
                Application.getAppID(),
                Application.getMEID(),
                Application.getNUserID(),
                Application.getInspectionUnitName(),
                Application.getInspectionUnitAdd()
        );
    }

    public int deleteApplicationByID(String ApplicationID) {
        String sql="update Application set LogicalAddDel=0,LastModification=now() where AppID=?";
        return jdbcTemplate.update(sql,ApplicationID);
    }


    public int updateApplication(Application Application) {
        String sql="update Application set AppID=?,MEID=?,NUserID=?," +
                "InspectionUnitName=?,InspectionUnitAdd=?,AppDate=?,LastModification=now() where AppID=?";
        return jdbcTemplate.update(sql,Application.getAppID(),
                Application.getMEID(),
                Application.getNUserID(),
                Application.getInspectionUnitName(),
                Application.getInspectionUnitAdd(),
                Application.getAppDate(),
                Application.getAppID());
    }


    public List<Map<String,Object>> selectApplicationByID(String ApplicationID) {
        String sql = "select * from Application where AppID = ?";
        return jdbcTemplate.queryForList(sql,ApplicationID);
    }



    public List<Map<String,Object>>getAllApplication() {
        String sql="select * from Application";
        return jdbcTemplate.queryForList(sql);
    }

}
